package jgl.vajra.operator.widget.dialogfragment;

import android.content.Context;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;

import jgl.vajra.operator.R;
import jgl.vajra.operator.databinding.DialogFragmentShareBinding;
import jgl.vajra.operator.listener.ShareDialogListener;
import jgl.vajra.operator.manager.UMShareManager;
import jgl.vajra.operator.widget.databindingadapter.BaseBindingItemPresenter;
import jgl.vajra.operator.widget.databindingadapter.SingleTypeBindingAdapter;

public class ShareDialogFragment extends BaseDialogFragment<DialogFragmentShareBinding> implements BaseBindingItemPresenter<Object> {

    private FragmentActivity activity;
    private String url;
    private String title;
    private String desc;
    private String image;
    private SingleTypeBindingAdapter adapter;
    private ShareDialogListener listener;

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_share;
    }

    @Override
    public void initView(Context context, View rootView, AttributeSet attrs) {
        mBinding.setView(this);
        mBinding.recyclerView.setLayoutManager(new GridLayoutManager(activity, 4));
       // adapter = new SingleTypeBindingAdapter(activity, ShareTypeBean.getShareTypeDataList(showBean), R.layout.item_fragment_share);
        adapter.setItemPresenter(this);
        mBinding.recyclerView.setAdapter(adapter);
        mBinding.recyclerView.setFocusableInTouchMode(false);
    }

    @Override
    public void initData(Context context) {

    }

    @Override
    public void initEvent(Context context) {

    }

    @Override
    public int getGravity() {
        return Gravity.BOTTOM;
    }

    public void onShareWx() {
        UMShareManager.getInstance().shareWx(activity, url, title, desc, image);
        dismiss();
    }

    public void onShareWxCircle() {
        UMShareManager.getInstance().shareWxCirCle(activity, url, title, desc, image);
        dismiss();
    }

    public void onShareSina() {
        UMShareManager.getInstance().shareSINA(activity, url, title, desc, image);
        dismiss();
    }

    public void onShareQQ() {
        UMShareManager.getInstance().shareQQ(activity, url, title, desc, image);
        dismiss();
    }

    public void onShareQQZone() {
        UMShareManager.getInstance().shareQQ(activity, url, title, desc, image);
        dismiss();
    }

    public void onShareTeahouse() {
        dismiss();
    }

    public void onDownloadLocal() {
        dismiss();
    }

    public void onNegative() {
        dismiss();
    }

    @Override
    public void onItemClick(int position, Object itemData) {

    }

  /*  public void setShareData(FragmentActivity activity, ShareInfoBean infoBean, ShareShowBean showBean, ShareDialogListener listener) {
        this.activity = activity;
        this.showBean = showBean;
        this.listener = listener;
        this.shareInfoBean = infoBean;
        this.url = infoBean.link;
        this.title = infoBean.title;
        this.intro = infoBean.intro;
        this.image = infoBean.img;
    }

    @Override
    public void onItemClick(int position, ShareTypeBean itemData) {
        switch (itemData.typeText) {
            case "分享给朋友":
                UMShareManager.getInstance().shareWx(activity, url, title, intro, image);
                dismiss();
                break;
            case "分享到朋友圈":
                UMShareManager.getInstance().shareWxCirCle(activity, url, title, intro, image);
                dismiss();
                break;
            case "分享到微博":
                UMShareManager.getInstance().shareSINA(activity, url, title, intro, image);
                dismiss();
                break;
            case "分享给好友":
                UMShareManager.getInstance().shareQQ(activity, url, title, intro, image);
                dismiss();
                break;
            case "分享到空间":
                UMShareManager.getInstance().shareQZone(activity, url, title, intro, image);
                dismiss();
                break;
            case "分享到茶馆":
                if (squareShareDialogFragment == null)
                    squareShareDialogFragment = FragmentManager.getSquareShareDialogFragment(shareInfoBean.resource_id,shareInfoBean.resource_type);
                squareShareDialogFragment.show(getActivity().getSupportFragmentManager());
                if (listener != null)
                    listener.onShareTeahouse();
                //dismiss();
                break;
            case "保存到本地":
                if (listener != null)
                    listener.onDownloadLocal();
                //dismiss();
                break;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (squareShareDialogFragment != null && squareShareDialogFragment.isShowing()) {
            squareShareDialogFragment.dismiss();
        }
        squareShareDialogFragment = null;
    }*/
}
